package game.players.cpu.teammate;

import com.uqbar.vainilla.appearances.Sprite;

import game.ball.SoccerBall;
import game.players.SoccerPlayer;
import game.players.SoccerPlayerCPU;
import game.players.states.WithoutBallSweepingPlayer;
import game.scene.MatchScene;

public class WithoutBallSweepingCPUMate extends WithoutBallSweepingPlayer {

	public WithoutBallSweepingCPUMate(SoccerPlayer player, boolean isRight) {
		super(player, isRight);
	}
	
	@Override
	protected void setRightSprite() {
		this.getPlayer().setAppearance(Sprite.fromImage("/images/goal3_barrida2.png").scale(1.5));
	}
	
	@Override
	protected void setLeftSprite() {
		this.getPlayer().setAppearance(Sprite.fromImage("/images/goal3_barrida2.png").scale(1.5).flipHorizontally());
	}
	
	@Override
	protected void takeTheBall(SoccerBall ball) {
		double advanceX = this.getPlayer().getX() - ball.getX() + ball.getRatio();
		double advanceY = this.getPlayer().getY() + this.getPlayer().getAppearance().getHeight() - ball.getY() - ball.getRatio();
		
		ball.moveNormally(advanceX, advanceY);
	}
	
	@Override
	public void snatchTheBall() {
		MatchScene scene = this.getPlayer().getScene();
		scene.changeFromSweepingCPUToUser(scene.getUserPlayer(), (SoccerPlayerCPU) this.getPlayer());
	}
	
	@Override
	public void takePossession(SoccerBall ball) {
		this.takeTheBall(ball);
		MatchScene scene = this.getPlayer().getScene();
		
		scene.changeFromSweepingCPUToUser(scene.getUserPlayer(), (SoccerPlayerCPU) this.getPlayer());
	}

	@Override
	public void finishSweep() {
		this.getUpPlayer();
		if (this.getPlayer().isWithBall())
			this.getPlayer().getScene().changeFromSweepingCPUToUser(this.getPlayer().getScene().getUserPlayer(), (SoccerPlayerCPU) this.getPlayer());
		else
			this.getPlayer().setState(new WithoutBallStationaryCPUMate(this.getPlayer()));
	}

}
